// mircoApp/video_popularize_award/detail/detail.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:"",
    title: "",
    language: "",
    video_url: '',
    no_rewards:app.data.host+'/static/local/video-promotion-rewards/no-rewards.png',
    page: 1,
    total_page: 0,
    cover_url: "",
    Imgurl: app.data.host+'/static/local/video-promotion-rewards/success.png',
    detail: {},
    show: false,
    record_list: [],
    popularize: false,
    member_list: [],
    nums:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.id = options.id;
    let language = wx.getStorageSync("langIndex");
    this.setData({
      language: language.en,
      popularize: false
    })
    this.getData()
    this.getVideo()
  },
  popularize_handle(){
      this.setData({popularize:false});
  },
  getVideo() {
    app._postNetWork({
      url: app.getNetAddresss("plugin.video-promotion-rewards.frontend.income.getShareUrl"),
      data: {
        id: this.data.id
      },
      success: resdata => {
        let {
          result,
          msg,
          data
        } = resdata.data;
        if (result) {
          this.data.video_url = data.url;
        } else {
          app.tips(msg);
        }
      }
    })
  },
  getData(page = 1) {
    app._postNetWork({
      url: app.getNetAddresss("plugin.video-promotion-rewards.frontend.income.getDetail"),
      data: {
        page,
        id: this.data.id
      },
      success: resdata => {
        let {
          result,
          msg,
          data
        } = resdata.data;
        if (result) {
          let member_list =data.member_list||[];
          this.setData({member_list,detail:data.detail,nums:member_list.length})
          if (data.member_list.length !== 0) {
            this.setData({popularize:true})
          }
          if (data.record_list.data.length !== 0) {
            let record_list = page == 1 ? data.record_list.data : this.data.record_list.concat(data.record_list.data);
            console.log(data.record_list,'data.record_list==');
            this.data.page = data.record_list.current_page;
            this.data.total_page = data.record_list.last_page;
            this.setData({record_list});
            console.log(this.data.page,this.data.total_page,'====');
          }
          page == 1 && this.getCoverImg(data.detail.video_id);
        } else {
          app.tips(msg);
        }
      }
    })

  },
  getCoverImg(video_goods_id) {
    app._getNetWork({
      url:app.getNetAddresss("plugin.video-share.frontend.video.getVideoGoods"),
      data:{video_goods_id},
      success:resdata=>{
        let {result,msg,data} = resdata.data;
        if(result){
          this.data.title = data.title;
          this.setData({
            cover_url:data.video_goods.cover
          })
        }else{
          app.tips(msg);
        }
      }
    })
  
  },
  share_handle() {
    this.setData({
      show: true
    });
  },
  close() {
    this.setData({
      show: false
    });
  },
  order() {
    wx.navigateTo({
      url: '/packageA/member/orderdetail/orderdetail?order_id='+this.data.detail.order_id+'&orderType=shop',
    })
  },
  copuM() {
    wx.setClipboardData({
      data: this.data.video_url,
      success:(res)=> {
        app.tips("复制成功");
        this.setData({show:false});
      },
      fail(err){
        app.tips('复制失败')
      }
    });
  },
  toVideo() {
    let mid = wx.getStorageSync("yz_uid")
    wx.navigateTo({
      url: `/packageC/video_goods/VideoDetail/VideoDetail?vid=${this.data.detail.video_id}&page=1&category=false&mid=${mid}`,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if(this.data.page>=this.data.total_page) return;
    let page =  this.data.page + 1;
    this.getData(page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    let mid = wx.getStorageSync("yz_uid")
    return {
      title: this.data.title,
      imageUrl: this.data.cover_url,
      path: '/packageC/video_goods/VideoDetail/VideoDetail?vid='+this.data.detail.video_id+'&mid='+mid
    }
  }
})